package com.yuantu.judiciary.dao;

import com.yuantu.judiciary.model.domain.QueryAuthorizationDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.sql.Timestamp;

/**
 * 查询授权数据库操作接口
 *
 * @author syw
 * @since 2023-07-12
 **/
public interface IQueryAuthorizationDao extends JpaRepository<QueryAuthorizationDO, Long> {

    QueryAuthorizationDO findFirstByQueryIdAndExpiresTimeGreaterThanEqualAndDeletedFalseOrderByCreateTimeDesc(Long queryId, Timestamp expiresTime);

    @Modifying
    @Query("update QueryAuthorizationDO set deleted = true where queryId = :queryId and deleted = false ")
    void deleteByQueryId(Long queryId);


    QueryAuthorizationDO findFirstByQueryIdAndDeletedFalseOrderByCreateTimeDesc(Long queryId);

}
